package com.wv.common.result;

import lombok.Data;

/**
 * 通用的结果返回类
 * @param <T>
 */
@Data
public class Result<T> {

    private Integer code;

    private String msg;

    private T data;

    public Result() {
        this.code = 200;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result error(String msg) {
        return new Result(HttpCodeEnum.ERROR.getCode(), msg);
    }

    public static Result ok(Object data) {
        return new Result(HttpCodeEnum.SUCCESS.getCode(), HttpCodeEnum.SUCCESS.getMsg(),data);
    }

    public static Result ok() {
        return new Result(HttpCodeEnum.SUCCESS.getCode(), HttpCodeEnum.SUCCESS.getMsg());
    }

    public static Result ok(String msg,Object data) {
        return new Result(HttpCodeEnum.SUCCESS.getCode(), msg,data);
    }

    public static Result error(HttpCodeEnum httpCodeEnum){
        return new Result(httpCodeEnum.getCode(),httpCodeEnum.getMsg());
    }
    public boolean checkSuccess(){
        return this.code == 200;
    }
}
